package com.guigu.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.guigu.constant.MessageConstant;
import com.guigu.entity.PageResult;
import com.guigu.entity.QueryPageBean;
import com.guigu.entity.Result;
import com.guigu.pojo.CheckGroup;
import com.guigu.pojo.CheckItem;
import com.guigu.service.SetmealService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Kc
 * @date 2021-04-25
 */
@RestController
@RequestMapping("/Setmeal")
public class SetmealController {
    @Reference
    private SetmealService setmealService;


    //分页查询
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult=setmealService.pageQuery(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString()
        );
        return pageResult;
    }

    @RequestMapping("/deleteById")
    public Result delete(Integer id){
        try {
            setmealService.deleteById2(id);
            return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return new Result(false, e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.DELETE_CHECKGROUP_FAIL);
        }
    }

    @RequestMapping("/findAll")
    public Result queryAll(){
        List<CheckGroup> checkGroups = setmealService.queryAll();
        if (checkGroups !=null && checkGroups.size()>0){
            Result result=new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS);
            result.setData(checkGroups);
            return result;
        }
        return new Result(false,MessageConstant.QUERY_CHECKITEM_FAIL);
    }
}
